<template>
	<view>

		  <view class="cu-list menu-avatar  card-menu martop" >

		    <view class="cu-item" v-for="(item,index) in lists" :key="index">

				<image class="cu-avatar round lg " :src='item.icon' @tap="toUserMain(item._id)"></image>


		      <view class="content">
		        <view class="text-grey">
		          <text class="text-cut">{{item.user_name}}</text>
<!-- 		          <view class="cu-tag round bg-orange sm">战士</view> -->
		        </view>
		        <view class="text-gray text-sm flex">
		          <text class="text-cut">{{item.characters.slice(0,2)+"..."}}</text>
		        </view>
		      </view>
		      <view class="action">
		        <view class="text-grey text-lg chat">
					<text class="chat"  @tap="toChat(item._id,item.user_name,item.icon)">聊天</text>
				</view>

		      </view>
		    </view>
		  </view>
		<!-- 聊天消息end -->
	</view>
</template>

<script>
	import data from "../../../datas/data.json"

	export default {
		data() {
			return {
				lists:[],
			}
		},
		onLoad(options) {
			let user_name=options.user_name;
			var that=this;
			console.log(user_name);
			uniCloud.callFunction({
				name:"searchUsers",
				data:{"name":user_name},
				success(res) {
					that.lists=res.result.users;
					if(that.lists.length==0){
						uni.showToast({
							title:"未搜索到",
							duration:1000
						})
					}
					// console.log(res.result.users);
				}
			})
		},
		onShow() {
			uni.setNavigationBarTitle({
				title:"搜索结果"
			})	
		},
		methods: {
			toUserMain(id){
				 uni.navigateTo({
					url:'../../user-detail/user-detail?user_id='+id
				 })
			},
			toChat(id,name,icon){
				//store.chat_datas.current_frend_icon=this.user_data.icon;
				uni.navigateTo({
					url:"../../msg/msg_chat/msg_chat?friend_id="+id+"&friend_name="+name+"&icon="+icon
				})
				// uni.navigateTo({
				// 	url:"../msg/msg_chat/msg_chat?friend_id="+id+"&friend_name="+name+"&icon="+icon
				// })
			},
			focus:function(index){},
		}
	}
</script>

<style scoped>
	.chat{
		background: #2B7FFC;
		color: white;
	}
</style>
